﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    class ImgManager
    {
        private ImgManager() { }

        public static Image Img { set; get; }

        public static void Prepare()
        {
            Img = Image.FromFile(@"res/img.jpg");
        }

        public static void Sample()
        {
            Img = Image.FromFile(@"res/img.jpg");
        }

        public static Func<int, int, Image> GenPart(int row, int col)
        {
            int ux = Img.Width / row, uy = Img.Height / col;
           
            return (int x, int y) =>
            {
                Image ret = new Bitmap(ux, uy, PixelFormat.Format24bppRgb);

                using(Graphics g = Graphics.FromImage(ret))
                {
                    g.DrawImage(Img, new Rectangle(0, 0, ux, uy), new Rectangle(x * ux, y * ux, ux, uy), GraphicsUnit.Pixel);
                }

                return ret;
            };
        }
    }
}
